exports.TutorialManager = Core.Class.singleton(
{
    classname: 'TutorialManager',
    
    initialize: function() 
    {
    	this._currentTutorialStep = null;
    	this._hasCompletedTutorial = null;
    	this._tutorialPopup = null;
    	
    	this._currentTutorialStep = MMGameState.getCurrentUser().getCurrentTutorialStep();
    	this._hasCompletedTutorial = MMGameState.getCurrentUser().getHasCompletedTutorial();
    	this.makeTutorialPopup();
    },
    
    getHasCompletedTutorial: function()
    {
    	return this._hasCompletedTutorial;
    },
    
    setHasCompletedTutorial: function(isActive)
    {
    	this._hasCompletedTutorial = isActive;
    	//MMGameState.getCurrentUser().setHasCompletedTutorial(isActive);
    	DatabaseHelper.setHasCompletedtutorial(isActive);
    },
    
    getCurrentTutorialStep: function()
    {
    	return this._currentTutorialStep;
    },
    
    setCurrentTutorialStep: function(currentStep)
    {
    	if(this.getCurrentTutorialStep() == 12)
    	{
    		this._currentTutorialStep = currentStep;
    		DatabaseHelper.setCurrentTutorialStep(currentStep);
    	}
    	else
    	{
	    	this._currentTutorialStep = currentStep;
	    	MMGameState.getCurrentUser().setCurrentTutorialStep(currentStep);
	    	MMGameState.getCurrentUser().updateModel();
    	}
    },    
    
    makeTutorialPopup: function()
 	{
 		if(!this.getHasCompletedTutorial())
 		{
	 		this._tutorialPopup = new GLTextAlert(Core.Localization.getString("TUTORIAL_TEXT_0"));
	 		this._tutorialPopup.createView();
	 		this._tutorialPopup.setPosition([TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(150)]);
	 		this._tutorialPopup.show();
 		}
 	},
 	
 	hideTutorialPopup: function()
 	{
 		if(this._tutorialPopup)
 		{
 			this._tutorialPopup.setVisible(false);
 		}
 	},
 	
 	unhideTutorialPopup: function()
 	{
 		if(this._tutorialPopup)
 		{
 			this._tutorialPopup.setVisible(true);
 		}
 	},
 	
 	getTutorialPopup: function()
 	{
// 		if(this._tutorialPopup)
// 		{
// 			this._tutorialPopup.destroy();
// 			this._tutorialPopup = null;
// 		}
// 		this.makeTutorialPopup();
 		return this._tutorialPopup;
 	},
    
    startTurorialAtCurrentStep: function()
    {
    	if(!this.getHasCompletedTutorial())
    	{
			MMGameLayer.getControlLayer().getBottomBar().disbaleMainMenuButton();
			switch(this._currentTutorialStep)
			{
				case 1:
					var storeContainer = MMGameLayer.getMallUI().getStoresUIArray().objectAtIndex(0);
					storeContainer.showTutorialForCoin();
				break;
				
				case 2:
					var storeContainer = MMGameLayer.getMallUI().getStoresUIArray().objectAtIndex(0);
					storeContainer.showTutorialForRestocking();
				break;
				
				case 3:
					var storeContainer = MMGameLayer.getMallUI().getStoresUIArray().objectAtIndex(0);
					storeContainer.showTutorialForInstantRestocking();
				break;
				
				case 4:
					var storeContainer = MMGameLayer.getMallUI().getStoresUIArray().objectAtIndex(0);
					storeContainer.showTutorialForUpgrade();
				break;
				
				case 5:
					var storeContainer = MMGameLayer.getMallUI().getStoresUIArray().objectAtIndex(0);
					storeContainer.showTutorialForInstantUpgrade();					
				break;
																			
				case 6:
					var bottomBar = MMGameLayer.getControlLayer().getBottomBar();
					bottomBar.enableMainMenuButton();
					bottomBar.showTutorialIndicatorForMenu();
				break;
				
				case 7:
					var bottomBar = MMGameLayer.getControlLayer().getBottomBar();
					bottomBar.enableMainMenuButton();
					bottomBar.showTutorialIndicatorForMenu();				
				break;

				case 8:
					var elevator = ElevatorHandler.getElevatorsUIArray().objectAtIndex(0);
					if(elevator)
					{
						elevator.showTutorialForUpgrade();
					}
				break;
				
				case 9:
					var elevator = ElevatorHandler.getElevatorsUIArray().objectAtIndex(0);
					if(elevator)
					{
						elevator.showTutorialForInstantUpgrade();
					}
				break;
					
				case 10:
					var bottomBar = MMGameLayer.getControlLayer().getBottomBar();
					bottomBar.enableMainMenuButton();
					bottomBar.showTutorialIndicatorForMenu();
				break;
					
				case 11:
					TrashHandler.showTutorialForTrash();
				break;
				
				case 12:
					var bottomBar = MMGameLayer.getControlLayer().getBottomBar();
					bottomBar.enableMainMenuButton();
					bottomBar.showTutorialIndicatorForMenu();
				break;
				
				case 13:
					this.finalizeTutorial();
					 
				break;
			}
    	}
    },
    
    finalizeTutorial: function()
    {
//    	var bottomBar = MMGameLayer.getControlLayer().getBottomBar();
//		bottomBar.enableMainMenuButton();
    	this.setHasCompletedTutorial(true);
    	if(this._tutorialPopup)
    	{
    		this._tutorialPopup.destroy();
    		this._tutorialPopup = null;
    	}
    	AnalyticsHandler.funnelStage("Tutorial",this._currentTutorial,"Complete "+this._currentTutorial+" TutorialScreen");
    	var alert = new GAGLAlertWindow("",Core.Localization.getString("TUTORIAL_TEXT_13"),this);
		alert.setTagValue(100);
		alert.show();
    },
    
    clickedButtonAtIndex: function(buttonIndex,alerWindow)
    {
    	if (buttonIndex == 0) 
		{
			if(alerWindow.getTagValue() == 100)
			{
				MMFriendActionManager.postFriendActionsDone();
				GameCentralHandler.addTransitionScreen();
				DatabaseInterface.loadUser();
				DatabaseHelper.unloadUser();
			}	
		} 
		else if (buttonIndex == 1)
		{
			
		}
    },
    
    showNextTutorialStep: function()
    {
    	if(!DatabaseInterface._isVisitingNeighbor)
    	{
	    	var nextStep = +this.getCurrentTutorialStep() + 1;
	    	this.setCurrentTutorialStep(nextStep);

	    	this.startTurorialAtCurrentStep();
    	}
    },

	getBaseResourcePath: function()
	{
		
	},
								   
	destroy: function()
    {
    	
    },
});
